import { create } from "zustand";
import { persist, createJSONStorage, devtools } from "zustand/middleware";

export const useAppStore = create(
  devtools(
    persist(
      (set) => ({
        appName: "配置中心平台",
        userInfo: {},
        isCollapse: false, // 是否折叠
        buttonPermissions: [1, 2],
        historyPath:[],// 存储历史路由
        setName: (name) => set({ appName: name }),
        setUserInfo: (info) => set({ userInfo: info }), // 更新用户信息
        setCollapse: (isCollapse) => set({ isCollapse }), // 更新折叠状态
        setHistoryPath: (path) => set({ historyPath: path }), // 更新历史路由
      }),
      {
        name: "app",
        storage: createJSONStorage(() => sessionStorage),
      }
    )
  )
);
